package com.meteor.controller;

import com.meteor.pojo.CommentDream;
import com.meteor.service.CommentDreamService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class CommentDreamController {

    @Resource
    private CommentDreamService commentDreamService;

    @Value("/image/img.png")
    private String avatar;

    /**
     * 来到关于我页面
     */
    @GetMapping("/aboutMe")
    public String aboutMe() {
        return "aboutMe";
    }


    /**
     * 进入关于梦想页面
     */
    @GetMapping("/dream")
    public String dream(Model model) {
        List<CommentDream> list = commentDreamService.list();
        model.addAttribute("comments", list);
        return "dream";
    }

    /**
     * 梦想评论
     */
    @PostMapping("/commentOne")
    public String comment(CommentDream commentDream,Model model) {
        commentDream.setPicture(avatar);
        commentDreamService.save(commentDream);
        List<CommentDream> list = commentDreamService.list();
        model.addAttribute("comments", list);
        return "dream::commentList";
    }


}
